package cn.smbms.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class MyBatiesUtil {
 private static    SqlSessionFactory factory =null;
    static{
        // 1 读取配置文件
        InputStream is = null;
        try {
            is = Resources.getResourceAsStream("configuration.xml");
            // 2 把配置文件给框架，
            factory = new SqlSessionFactoryBuilder().build(is);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
    public  static SqlSession createSession(){
         return factory.openSession();

    }
    public static void closeSqlSession(SqlSession sqlSession){
        if (null!= sqlSession)
        sqlSession.close();
    }
}
